
//banner 
let oBnimg = document.getElementById('bnimg');
let oBnli = document.getElementsByClassName('bnli');
class BnImg{
    constructor(oBnImg,oBnli,time){
        this.oBnImg = oBnImg;
        this.oBnli = oBnli;
        this.time = time;
        this.index = 0;
        this.res = 0;
        let that = this;
        $.get("goodsAndShoppingCart/bannerGet.php",function(restext){
            that.res = restext;
        },"json")
        this.oBnImg.src = `img/${this.index}.jpg`;
        this.oBnli[this.index].style.backgroundColor = '#ffc933';
        this.eventBind();
    }

    updateBg() {
        this.oBnImg.src = `${this.res[this.index].img}`;
        for (let i = 0; i < this.oBnli.length; i++) {
            if (i == this.index) {
                this.oBnli[i].style.backgroundColor = '#ffc933'
            } else {
                this.oBnli[i].style.background = 'rgba(255,255,255,0.2)'
            }
        }
    }

    clickLi() {
        let that = this;
        for (let i = 0; i < this.oBnli.length; i++) {
            this.oBnli[i].onclick = function () {
                that.index = i;
                that.updateBg()
            }
        }
    }
    interval() {
        let that = this;
        this.time = setInterval(function () {
            that.index++;
            if (that.index == that.oBnli.length) {
                that.index = 0;
            }
            that.updateBg();
        }, 3000)
    }
    clear() {
        clearInterval(this.time)
    }
    eventBind(){
        let that = this;
        this.clickLi();
        this.interval();
        this.oBnImg.onmouseover = function(){
            that.clear();
        }
        this.oBnImg.onmouseout = function(){
            that.interval();
        }
    }

}
let c = new BnImg(oBnimg,oBnli);
// 主页新品接口
    $.get("goodsAndShoppingCart/getGoodsListNew.php","typeId=007&&count=4" ,function (restext) {
        console.log(restext);
        for(let j=0;j< $(".newgoodImg").length;j++){
            let i=j;
            $(".newgoodImg").eq(j).attr('src',`${restext[i].goodsImg}`);
            $(".newgoodName").eq(j).html(`${restext[i].goodsName}`);
            $(".newgoodPrice").eq(j).html("￥"+`${restext[i].goodsPrice}`);
        }   
    },"json");
    
